package com.headwind.logistics.carrier.controller;

import com.headwind.logistics.carrier.dto.SimDto;
import com.headwind.logistics.carrier.service.inter.SimServiceInter;
import com.headwind.logistics.common.pojo.Car;
import com.headwind.logistics.common.pojo.Employee;
import com.headwind.logistics.common.pojo.Sim;
import com.headwind.logistics.common.util.LayuiUtil;
import com.headwind.logistics.common.util.RestResult;
import com.headwind.logistics.common.util.ResultGenerator;
import com.headwind.logistics.log.annotate.Log;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author QT
 * @Date 2020/7/27 9:43
 * @Version 1.0
 * @DESCRIPTION sim卡控制器层
 */
@Controller
public class SimController {
    //sim卡业务逻辑接口层
    @Resource
    private SimServiceInter simServiceInter;
    //api统一响应格式
    @Resource
    private ResultGenerator resultGenerator;
    /**
     *  查询Sim卡数据和模糊查询并分页
     *  @param page 页码
     *  @param limit 行数
     * @return
     */
    @GetMapping("/admin/carrier/queryAllSim")
    @ResponseBody
    @Log("查询Sim卡信息并分页")
    public LayuiUtil queryAllSim(String simCard,Integer page,Integer limit){
        List<SimDto> list=simServiceInter.queryAllSim(simCard,page,limit);
        return LayuiUtil.data(simServiceInter.queryAllSim(simCard,null,null).size(),list);
    }
    /**
     * 修改Sim卡状态和领取时间
     * @param sim sim实体对象
     * @return
     */
    @PostMapping("/admin/carrier/updateStatusAndGetTime")
    @ResponseBody
    @Log("修改Sim卡状态和领取时间")
    public RestResult updateStatusAndGetTime(Sim sim){
        int count=simServiceInter.updateStatusAndGetTime(sim);
        if(count>0){
            return resultGenerator.getSuccessResult("更改成功",count);
        }
        return resultGenerator.getFailResult("更改失败",count);
    }
    /**
     * 修改sim卡状态
     * @param sim sim实体对象
     * @return
     */
    @PostMapping("/admin/carrier/updateStatus")
    @ResponseBody
    @Log("修改Sim卡状态")
    public RestResult updateStatus(Sim sim){
        int count=simServiceInter.updateStatus(sim);
        if(count>0){
            return resultGenerator.getSuccessResult("更改成功",count);
        }
        return resultGenerator.getFailResult("更改失败",count);
    }
    /**
     * 新增sim卡信息
     * @param sim sim实体对象
     * @return
     */
    @PostMapping("/admin/carrier/addSim")
    @ResponseBody
    @Log("新增Sim卡信息")
    public RestResult addSim(Sim sim){
        int count=simServiceInter.addSim(sim);
        if(count>0){
            return resultGenerator.getSuccessResult("新增成功",count);
        }
        return resultGenerator.getFailResult("新增失败",count);
    }

    /**
     * 查询所有车牌号
     * @return
     */
    @GetMapping("/admin/carrier/queryCarNumber")
    @ResponseBody
    @Log("查询所有车牌号")
    public List<Car> queryAllCarNumber() {
        List<Car> list= simServiceInter.queryAllCarNumber();
        return  list;
    }
    /**
     * 根据ID删除Sim信息
     * @param sim sim实体对象
     * @return
     */
    @PostMapping("/admin/carrier/deleteSim")
    @ResponseBody
    @Log("删除Sim卡信息")
    public RestResult deleteSim(Sim sim) {
        int count=simServiceInter.deleteSim(sim);
        if(count>0){
            return resultGenerator.getSuccessResult("删除成功",count);
        }
        return resultGenerator.getFailResult("删除失败",count);
    }
}
